/*     */ package com.zimbra.cs.fb;
/*     */ 
/*     */ import com.zimbra.common.account.Key.AccountBy;
/*     */ import com.zimbra.common.httpclient.HttpClientUtil;
/*     */ import com.zimbra.common.localconfig.KnownKey;
/*     */ import com.zimbra.common.localconfig.LC;
/*     */ import com.zimbra.common.service.ServiceException;
/*     */ import com.zimbra.common.soap.Element;
/*     */ import com.zimbra.common.soap.XmlParseException;
/*     */ import com.zimbra.common.util.ByteUtil;
/*     */ import com.zimbra.common.util.DateUtil;
/*     */ import com.zimbra.common.util.Log;
/*     */ import com.zimbra.common.util.ZimbraHttpConnectionManager;
/*     */ import com.zimbra.common.util.ZimbraLog;
/*     */ import com.zimbra.cs.account.Account;
/*     */ import com.zimbra.cs.account.Config;
/*     */ import com.zimbra.cs.account.Domain;
/*     */ import com.zimbra.cs.account.Provisioning;
/*     */ import com.zimbra.cs.httpclient.HttpProxyUtil;
/*     */ import com.zimbra.cs.mailbox.MailItem.Type;
/*     */ import java.io.IOException;
/*     */ import java.io.InputStream;
/*     */ import java.net.URLEncoder;
/*     */ import java.util.ArrayList;
/*     */ import java.util.Calendar;
/*     */ import java.util.Date;
/*     */ import java.util.EnumSet;
/*     */ import java.util.GregorianCalendar;
/*     */ import java.util.HashMap;
/*     */ import java.util.Iterator;
/*     */ import java.util.List;
/*     */ import java.util.Map;
/*     */ import java.util.Map.Entry;
/*     */ import java.util.Set;
/*     */ import org.apache.commons.httpclient.Credentials;
/*     */ import org.apache.commons.httpclient.Header;
/*     */ import org.apache.commons.httpclient.HttpClient;
/*     */ import org.apache.commons.httpclient.HttpMethod;
/*     */ import org.apache.commons.httpclient.HttpState;
/*     */ import org.apache.commons.httpclient.UsernamePasswordCredentials;
/*     */ import org.apache.commons.httpclient.auth.AuthScope;
/*     */ import org.apache.commons.httpclient.methods.ByteArrayRequestEntity;
/*     */ import org.apache.commons.httpclient.methods.GetMethod;
/*     */ import org.apache.commons.httpclient.methods.PostMethod;
/*     */ import org.apache.commons.httpclient.params.HttpClientParams;
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ public class ExchangeFreeBusyProvider
/*     */   extends FreeBusyProvider
/*     */ {
/*     */   public static final String USER_AGENT = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)";
/*     */   public static final int MULTI_STATUS = 207;
/*     */   public static final String TYPE_WEBDAV = "webdav";
/*     */   
/*     */   public static enum AuthScheme
/*     */   {
/*  69 */     basic,  form;
/*     */     
/*     */     private AuthScheme() {}
/*     */   }
/*     */   
/*     */   public static class ServerInfo {
/*     */     public boolean enabled;
/*     */     public String url;
/*     */     public String org;
/*     */     public String cn;
/*     */     public String authUsername;
/*     */     public String authPassword;
/*     */     public ExchangeFreeBusyProvider.AuthScheme scheme;
/*     */   }
/*     */   
/*     */   public static abstract interface ExchangeUserResolver { public abstract ExchangeFreeBusyProvider.ServerInfo getServerInfo(String paramString);
/*     */   }
/*     */   
/*  87 */   private static class BasicUserResolver implements ExchangeFreeBusyProvider.ExchangeUserResolver { public ExchangeFreeBusyProvider.ServerInfo getServerInfo(String emailAddr) { String url = getAttr("zimbraFreebusyExchangeURL", emailAddr);
/*  88 */       String user = getAttr("zimbraFreebusyExchangeAuthUsername", emailAddr);
/*  89 */       String pass = getAttr("zimbraFreebusyExchangeAuthPassword", emailAddr);
/*  90 */       String scheme = getAttr("zimbraFreebusyExchangeAuthScheme", emailAddr);
/*  91 */       if ((url == null) || (user == null) || (pass == null) || (scheme == null)) {
/*  92 */         return null;
/*     */       }
/*  94 */       ExchangeFreeBusyProvider.ServerInfo info = new ExchangeFreeBusyProvider.ServerInfo();
/*  95 */       info.url = url;
/*  96 */       info.authUsername = user;
/*  97 */       info.authPassword = pass;
/*  98 */       info.scheme = ExchangeFreeBusyProvider.AuthScheme.valueOf(scheme);
/*  99 */       info.org = getAttr("zimbraFreebusyExchangeUserOrg", emailAddr);
/*     */       try {
/* 101 */         Account acct = null;
/* 102 */         if (emailAddr != null) {
/* 103 */           acct = Provisioning.getInstance().get(Key.AccountBy.name, emailAddr);
/*     */         }
/* 105 */         if (acct != null) {
/* 106 */           String[] fps = acct.getMultiAttr("zimbraForeignPrincipal");
/* 107 */           if ((fps != null) && (fps.length > 0)) {
/* 108 */             for (String fp : fps) {
/* 109 */               if (fp.startsWith("ad:")) {
/* 110 */                 int idx = fp.indexOf(':');
/* 111 */                 if (idx != -1) {
/* 112 */                   info.cn = fp.substring(idx + 1);
/* 113 */                   break;
/*     */                 }
/*     */               }
/*     */             }
/*     */           }
/*     */         }
/*     */       } catch (ServiceException se) {
/* 120 */         info.cn = null;
/*     */       }
/* 122 */       String exchangeType = getAttr("zimbraFreebusyExchangeServerType", emailAddr);
/* 123 */       info.enabled = "webdav".equals(exchangeType);
/* 124 */       return info;
/*     */     }
/*     */     
/*     */     static String getAttr(String attr, String emailAddr) {
/* 128 */       String val = null;
/* 129 */       if (attr == null)
/* 130 */         return val;
/*     */       try {
/* 132 */         Provisioning prov = Provisioning.getInstance();
/* 133 */         if (emailAddr != null) {
/* 134 */           Account acct = prov.get(Key.AccountBy.name, emailAddr);
/* 135 */           if (acct != null) {
/* 136 */             val = acct.getAttr(attr, null);
/* 137 */             if (val != null)
/* 138 */               return val;
/* 139 */             Domain dom = prov.getDomain(acct);
/* 140 */             if (dom != null)
/* 141 */               val = dom.getAttr(attr, null);
/* 142 */             if (val != null)
/* 143 */               return val;
/*     */           }
/*     */         }
/* 146 */         val = prov.getConfig().getAttr(attr, null);
/*     */       } catch (ServiceException se) {
/* 148 */         ZimbraLog.fb.error("can't get attr " + attr, se);
/*     */       }
/* 150 */       return val;
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/* 156 */   private static ArrayList<ExchangeUserResolver> sRESOLVERS = new ArrayList();
/*     */   
/* 158 */   static { registerResolver(new BasicUserResolver(null), 0);
/* 159 */     register(new ExchangeFreeBusyProvider());
/*     */   }
/*     */   
/*     */   public static void registerResolver(ExchangeUserResolver r, int priority) {
/* 163 */     synchronized (sRESOLVERS) {
/* 164 */       sRESOLVERS.ensureCapacity(priority + 1);
/* 165 */       sRESOLVERS.add(priority, r);
/*     */     }
/*     */   }
/*     */   
/*     */   public FreeBusyProvider getInstance()
/*     */   {
/* 171 */     return new ExchangeFreeBusyProvider();
/*     */   }
/*     */   
/*     */   public void addFreeBusyRequest(FreeBusyProvider.Request req) throws FreeBusyProvider.FreeBusyUserNotFoundException
/*     */   {
/* 176 */     ServerInfo info = null;
/* 177 */     for (ExchangeUserResolver resolver : sRESOLVERS) {
/* 178 */       String email = req.email;
/* 179 */       if (req.requestor != null)
/* 180 */         email = req.requestor.getName();
/* 181 */       info = resolver.getServerInfo(email);
/* 182 */       if (info != null)
/*     */         break;
/*     */     }
/* 185 */     if (info == null)
/* 186 */       throw new FreeBusyProvider.FreeBusyUserNotFoundException();
/* 187 */     if (!info.enabled)
/* 188 */       throw new FreeBusyProvider.FreeBusyUserNotFoundException();
/* 189 */     addRequest(info, req);
/*     */   }
/*     */   
/*     */   private void addRequest(ServerInfo info, FreeBusyProvider.Request req) {
/* 193 */     ArrayList<FreeBusyProvider.Request> r = (ArrayList)this.mRequests.get(info.url);
/* 194 */     if (r == null) {
/* 195 */       r = new ArrayList();
/* 196 */       this.mRequests.put(info.url, r);
/*     */     }
/* 198 */     req.data = info;
/* 199 */     r.add(req);
/*     */   }
/*     */   
/*     */ 
/*     */   public List<FreeBusy> getResults()
/*     */   {
/* 205 */     ArrayList<FreeBusy> ret = new ArrayList();
/* 206 */     for (Map.Entry<String, ArrayList<FreeBusyProvider.Request>> entry : this.mRequests.entrySet()) {
/*     */       try {
/* 208 */         ret.addAll(getFreeBusyForHost((String)entry.getKey(), (ArrayList)entry.getValue()));
/*     */       } catch (IOException e) {
/* 210 */         ZimbraLog.fb.error("error communicating with " + (String)entry.getKey(), e);
/* 211 */         return getEmptyList((ArrayList)entry.getValue());
/*     */       }
/*     */     }
/* 214 */     return ret;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   public String foreignPrincipalPrefix()
/*     */   {
/* 223 */     return "ad:";
/*     */   }
/*     */   
/*     */   public String getName()
/*     */   {
/* 228 */     return "EXCHANGE";
/*     */   }
/*     */   
/*     */   public Set<MailItem.Type> registerForItemTypes()
/*     */   {
/* 233 */     return EnumSet.of(MailItem.Type.APPOINTMENT);
/*     */   }
/*     */   
/*     */   public boolean registerForMailboxChanges()
/*     */   {
/* 238 */     return registerForMailboxChanges(null);
/*     */   }
/*     */   
/*     */   public boolean registerForMailboxChanges(String accountId)
/*     */   {
/* 243 */     String email = null;
/*     */     try {
/* 245 */       Account account = null;
/* 246 */       if (accountId != null)
/* 247 */         account = Provisioning.getInstance().getAccountById(accountId);
/* 248 */       if (account != null)
/* 249 */         email = account.getName();
/*     */     } catch (ServiceException se) {
/* 251 */       ZimbraLog.fb.warn("cannot fetch account", se);
/*     */     }
/* 253 */     return getServerInfo(email) != null;
/*     */   }
/*     */   
/*     */   private long getTimeInterval(String attr, String accountId, long defaultValue) throws ServiceException {
/* 257 */     Provisioning prov = Provisioning.getInstance();
/* 258 */     if (accountId != null) {
/* 259 */       Account acct = prov.get(Key.AccountBy.id, accountId);
/* 260 */       if (acct != null) {
/* 261 */         return acct.getTimeInterval(attr, defaultValue);
/*     */       }
/*     */     }
/* 264 */     return prov.getConfig().getTimeInterval(attr, defaultValue);
/*     */   }
/*     */   
/*     */   public long cachedFreeBusyStartTime(String accountId)
/*     */   {
/* 269 */     Calendar cal = GregorianCalendar.getInstance();
/* 270 */     int curYear = cal.get(1);
/*     */     try {
/* 272 */       long dur = getTimeInterval("zimbraFreebusyExchangeCachedIntervalStart", accountId, 0L);
/* 273 */       cal.setTimeInMillis(System.currentTimeMillis() - dur);
/*     */     }
/*     */     catch (ServiceException se) {
/* 276 */       cal.setTimeInMillis(System.currentTimeMillis() - 604800000L);
/*     */     }
/*     */     
/* 279 */     cal.set(11, 0);
/* 280 */     cal.set(12, 0);
/* 281 */     cal.set(13, 0);
/* 282 */     if (cal.get(1) < curYear)
/*     */     {
/*     */ 
/* 285 */       cal.set(curYear, 0, 1);
/*     */     }
/* 287 */     return cal.getTimeInMillis();
/*     */   }
/*     */   
/*     */   public long cachedFreeBusyEndTime(String accountId)
/*     */   {
/* 292 */     long duration = 5356800000L;
/* 293 */     Calendar cal = GregorianCalendar.getInstance();
/*     */     try {
/* 295 */       duration = getTimeInterval("zimbraFreebusyExchangeCachedInterval", accountId, duration);
/*     */     }
/*     */     catch (ServiceException se) {}
/* 298 */     cal.setTimeInMillis(cachedFreeBusyStartTime(accountId) + duration);
/*     */     
/* 300 */     cal.set(11, 0);
/* 301 */     cal.set(12, 0);
/* 302 */     cal.set(13, 0);
/* 303 */     return cal.getTimeInMillis();
/*     */   }
/*     */   
/*     */   public long cachedFreeBusyStartTime()
/*     */   {
/* 308 */     return cachedFreeBusyStartTime(null);
/*     */   }
/*     */   
/*     */   public long cachedFreeBusyEndTime()
/*     */   {
/* 313 */     return cachedFreeBusyEndTime(null);
/*     */   }
/*     */   
/*     */   public boolean handleMailboxChange(String accountId)
/*     */   {
/* 318 */     String email = getEmailAddress(accountId);
/* 319 */     ServerInfo serverInfo = getServerInfo(email);
/* 320 */     if ((email == null) || (!serverInfo.enabled)) {
/* 321 */       return true;
/*     */     }
/*     */     FreeBusy fb;
/*     */     try {
/* 325 */       fb = getFreeBusy(accountId, -1);
/*     */     } catch (ServiceException se) {
/* 327 */       ZimbraLog.fb.warn("can't get freebusy for account " + accountId, se);
/*     */       
/* 329 */       return !se.isReceiversFault();
/*     */     }
/* 331 */     if ((email == null) || (fb == null)) {
/* 332 */       ZimbraLog.fb.warn("account not found / incorrect / wrong host: " + accountId);
/* 333 */       return true;
/*     */     }
/* 335 */     if ((serverInfo == null) || (serverInfo.org == null) || (serverInfo.cn == null)) {
/* 336 */       ZimbraLog.fb.warn("no exchange server info for user " + email);
/* 337 */       return true;
/*     */     }
/* 339 */     ExchangeMessage msg = new ExchangeMessage(serverInfo.org, serverInfo.cn, email);
/* 340 */     String url = serverInfo.url + msg.getUrl();
/*     */     
/* 342 */     HttpMethod method = null;
/*     */     try
/*     */     {
/* 345 */       ZimbraLog.fb.debug("POST " + url);
/* 346 */       method = msg.createMethod(url, fb);
/* 347 */       method.setRequestHeader("Translate", "f");
/* 348 */       int status = sendRequest(method, serverInfo);
/* 349 */       if (status != 207) {
/* 350 */         resp = method.getResponseBodyAsStream();
/* 351 */         String respStr = resp == null ? "" : new String(ByteUtil.readInput(resp, 1024, 1024), "UTF-8");
/* 352 */         ZimbraLog.fb.error("cannot modify resource at %s : http error %d, buf (%s)", new Object[] { url, Integer.valueOf(status), respStr });
/* 353 */         return false;
/*     */       }
/*     */     } catch (IOException ioe) { InputStream resp;
/* 356 */       ZimbraLog.fb.error("error communicating with " + serverInfo.url, ioe);
/* 357 */       return 0;
/*     */     } finally {
/* 359 */       method.releaseConnection();
/*     */     }
/* 361 */     return true;
/*     */   }
/*     */   
/*     */   private int sendRequest(HttpMethod method, ServerInfo info) throws IOException {
/* 365 */     method.setDoAuthentication(true);
/* 366 */     method.setRequestHeader("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.1.4322)");
/* 367 */     HttpClient client = ZimbraHttpConnectionManager.getExternalHttpConnMgr().newHttpClient();
/* 368 */     HttpProxyUtil.configureProxy(client);
/* 369 */     switch (info.scheme) {
/*     */     case basic: 
/* 371 */       basicAuth(client, info);
/* 372 */       break;
/*     */     case form: 
/* 374 */       formAuth(client, info);
/*     */     }
/*     */     
/* 377 */     return HttpClientUtil.executeMethod(client, method);
/*     */   }
/*     */   
/*     */   private boolean basicAuth(HttpClient client, ServerInfo info) {
/* 381 */     HttpState state = new HttpState();
/* 382 */     Credentials cred = new UsernamePasswordCredentials(info.authUsername, info.authPassword);
/* 383 */     state.setCredentials(AuthScope.ANY, cred);
/* 384 */     client.setState(state);
/* 385 */     ArrayList<String> authPrefs = new ArrayList();
/* 386 */     authPrefs.add("Basic");
/* 387 */     client.getParams().setParameter("http.auth.scheme-priority", authPrefs);
/* 388 */     return true;
/*     */   }
/*     */   
/*     */   private boolean formAuth(HttpClient client, ServerInfo info) throws IOException {
/* 392 */     StringBuilder buf = new StringBuilder();
/* 393 */     buf.append("destination=");
/* 394 */     buf.append(URLEncoder.encode(info.url, "UTF-8"));
/* 395 */     buf.append("&username=");
/* 396 */     buf.append(info.authUsername);
/* 397 */     buf.append("&password=");
/* 398 */     buf.append(URLEncoder.encode(info.authPassword, "UTF-8"));
/* 399 */     buf.append("&flags=0");
/* 400 */     buf.append("&SubmitCreds=Log On");
/* 401 */     buf.append("&trusted=0");
/* 402 */     String url = info.url + LC.calendar_exchange_form_auth_url.value();
/* 403 */     PostMethod method = new PostMethod(url);
/* 404 */     ByteArrayRequestEntity re = new ByteArrayRequestEntity(buf.toString().getBytes(), "x-www-form-urlencoded");
/* 405 */     method.setRequestEntity(re);
/* 406 */     HttpState state = new HttpState();
/* 407 */     client.setState(state);
/*     */     try {
/* 409 */       int status = HttpClientUtil.executeMethod(client, method);
/* 410 */       if (status >= 400) {
/* 411 */         ZimbraLog.fb.error("form auth to Exchange returned an error: " + status);
/* 412 */         return false;
/*     */       }
/*     */     } finally {
/* 415 */       method.releaseConnection();
/*     */     }
/* 417 */     return true;
/*     */   }
/*     */   
/*     */   ExchangeFreeBusyProvider() {
/* 421 */     this.mRequests = new HashMap();
/*     */   }
/*     */   
/*     */   public List<FreeBusy> getFreeBusyForHost(String host, ArrayList<FreeBusyProvider.Request> req) throws IOException {
/* 425 */     ArrayList<FreeBusy> ret = new ArrayList();
/* 426 */     int fb_interval = LC.exchange_free_busy_interval_min.intValueWithinRange(5, 1444);
/* 427 */     FreeBusyProvider.Request r = (FreeBusyProvider.Request)req.get(0);
/* 428 */     ServerInfo serverInfo = (ServerInfo)r.data;
/* 429 */     if (serverInfo == null) {
/* 430 */       ZimbraLog.fb.warn("no exchange server info for user " + r.email);
/* 431 */       return ret;
/*     */     }
/* 433 */     if (!serverInfo.enabled) {
/* 434 */       return ret;
/*     */     }
/* 436 */     String url = constructGetUrl(serverInfo, req);
/* 437 */     ZimbraLog.fb.debug("fetching fb from url=" + url);
/* 438 */     HttpMethod method = new GetMethod(url);
/*     */     
/*     */ 
/* 441 */     Element response = null;
/*     */     try {
/* 443 */       int status = sendRequest(method, serverInfo);
/* 444 */       if (status != 200)
/* 445 */         return getEmptyList(req);
/* 446 */       if (ZimbraLog.fb.isDebugEnabled()) {
/* 447 */         cl = method.getResponseHeader("Content-Length");
/* 448 */         int contentLength = 10240;
/* 449 */         if (cl != null)
/* 450 */           contentLength = Integer.valueOf(((Header)cl).getValue()).intValue();
/* 451 */         String buf = new String(ByteUtil.readInput(method.getResponseBodyAsStream(), contentLength, contentLength), "UTF-8");
/*     */         
/* 453 */         ZimbraLog.fb.debug(buf);
/* 454 */         response = Element.parseXML(buf);
/*     */       } else {
/* 456 */         response = Element.parseXML(method.getResponseBodyAsStream());
/*     */       }
/* 458 */     } catch (XmlParseException e) { ZimbraLog.fb.warn("error parsing fb response from exchange", e);
/* 459 */       return getEmptyList(req);
/*     */     } catch (IOException e) { Object cl;
/* 461 */       ZimbraLog.fb.warn("error parsing fb response from exchange", e);
/* 462 */       return getEmptyList(req);
/*     */     } finally {
/* 464 */       method.releaseConnection();
/*     */     }
/* 466 */     for (FreeBusyProvider.Request re : req) {
/* 467 */       String fb = getFbString(response, re.email);
/* 468 */       ret.add(new ExchangeUserFreeBusy(fb, re.email, fb_interval, re.start, re.end));
/*     */     }
/* 470 */     return ret;
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/*     */   private String constructGetUrl(ServerInfo info, ArrayList<FreeBusyProvider.Request> req)
/*     */   {
/* 480 */     int fb_interval = LC.exchange_free_busy_interval_min.intValueWithinRange(5, 1444);
/* 481 */     long start = FreeBusyProvider.Request.offsetInterval(((FreeBusyProvider.Request)req.get(0)).start, fb_interval);
/* 482 */     StringBuilder buf = new StringBuilder(info.url);
/* 483 */     buf.append("/public/?cmd=freebusy");
/* 484 */     buf.append("&start=").append(DateUtil.toISO8601(new Date(start)));
/* 485 */     buf.append("&end=").append(DateUtil.toISO8601(new Date(((FreeBusyProvider.Request)req.get(0)).end)));
/* 486 */     buf.append("&interval=").append(fb_interval);
/* 487 */     for (FreeBusyProvider.Request r : req)
/* 488 */       buf.append("&u=SMTP:").append(r.email);
/* 489 */     return buf.toString();
/*     */   }
/*     */   
/*     */   private String getFbString(Element fbxml, String emailAddr) {
/* 493 */     String ret = "";
/* 494 */     Element node = fbxml.getOptionalElement("recipients");
/* 495 */     if (node != null) {
/* 496 */       for (Iterator i$ = node.listElements("item").iterator(); i$.hasNext(); 
/*     */           
/*     */ 
/*     */ 
/*     */ 
/* 501 */           goto 107)
/*     */       {
/* 496 */         Element e = (Element)i$.next();
/* 497 */         Element email = e.getOptionalElement("email");
/* 498 */         if ((email != null) && (email.getText().trim().equalsIgnoreCase(emailAddr))) {
/* 499 */           Element fb = e.getOptionalElement("fbdata");
/* 500 */           if (fb == null) break;
/* 501 */           ret = fb.getText();
/*     */         }
/*     */       }
/*     */     }
/*     */     
/*     */ 
/* 507 */     return ret;
/*     */   }
/*     */   
/*     */   public ServerInfo getServerInfo(String emailAddr) {
/* 511 */     ServerInfo serverInfo = null;
/* 512 */     for (ExchangeUserResolver r : sRESOLVERS) {
/* 513 */       serverInfo = r.getServerInfo(emailAddr);
/* 514 */       if (serverInfo != null)
/*     */         break;
/*     */     }
/* 517 */     return serverInfo;
/*     */   }
/*     */   
/*     */   public static int checkAuth(ServerInfo info, Account requestor) throws ServiceException, IOException {
/* 521 */     ExchangeFreeBusyProvider prov = new ExchangeFreeBusyProvider();
/* 522 */     ArrayList<FreeBusyProvider.Request> req = new ArrayList();
/* 523 */     req.add(new FreeBusyProvider.Request(requestor, requestor.getName(), prov.cachedFreeBusyStartTime(), prov.cachedFreeBusyEndTime(), -1));
/*     */     
/*     */ 
/*     */ 
/*     */ 
/*     */ 
/* 529 */     String url = prov.constructGetUrl(info, req);
/*     */     
/* 531 */     HttpMethod method = new GetMethod(url);
/*     */     try {
/* 533 */       return prov.sendRequest(method, info);
/*     */     } finally {
/* 535 */       method.releaseConnection();
/*     */     }
/*     */   }
/*     */   
/*     */ 
/*     */ 
/*     */ 
/*     */   private Map<String, ArrayList<FreeBusyProvider.Request>> mRequests;
/*     */   
/*     */ 
/*     */   private static final String EXCHANGE = "EXCHANGE";
/*     */   
/*     */ 
/*     */   private static final String HEADER_USER_AGENT = "User-Agent";
/*     */   
/*     */ 
/*     */   private static final String HEADER_TRANSLATE = "Translate";
/*     */   
/*     */ 
/*     */   public static class ExchangeUserFreeBusy
/*     */     extends FreeBusy
/*     */   {
/* 557 */     private final char FREE = '0';
/* 558 */     private final char TENTATIVE = '1';
/* 559 */     private final char BUSY = '2';
/* 560 */     private final char UNAVAILABLE = '3';
/* 561 */     private final char NODATA = '4';
/*     */     
/*     */     protected ExchangeUserFreeBusy(String fb, String emailAddr, int interval, long start, long end) {
/* 564 */       super(start, end);
/* 565 */       parseInterval(fb, emailAddr, interval, start, end);
/*     */     }
/*     */     
/* 568 */     private void parseInterval(String fb, String emailAddr, int interval, long start, long end) { long intervalInMillis = interval * 60L * 1000L;
/* 569 */       long maskedStart = FreeBusyProvider.Request.offsetInterval(start, interval);
/* 570 */       if (maskedStart < start) {
/* 571 */         end = maskedStart + intervalInMillis;
/*     */       } else {
/* 573 */         end = start + intervalInMillis;
/*     */       }
/* 575 */       for (int i = 0; i < fb.length(); i++) {
/* 576 */         switch (fb.charAt(i)) {
/*     */         case '1': 
/* 578 */           this.mList.addInterval(new FreeBusy.Interval(start, end, "T"));
/* 579 */           break;
/*     */         case '2': 
/* 581 */           this.mList.addInterval(new FreeBusy.Interval(start, end, "B"));
/* 582 */           break;
/*     */         case '3': 
/* 584 */           this.mList.addInterval(new FreeBusy.Interval(start, end, "O"));
/* 585 */           break;
/*     */         case '4': 
/* 587 */           this.mList.addInterval(new FreeBusy.Interval(start, end, "N"));
/* 588 */           break;
/*     */         }
/*     */         
/*     */         
/*     */ 
/* 593 */         start = end;
/* 594 */         end = start + intervalInMillis;
/*     */       }
/*     */     }
/*     */   }
/*     */ }


/* Location:              /home/mint/zimbrastore.jar!/com/zimbra/cs/fb/ExchangeFreeBusyProvider.class
 * Java compiler version: 7 (51.0)
 * JD-Core Version:       0.7.1
 */